data "google_billing_account" "account" {
  billing_account = "<%= ctx[:test_env_vars]['billing_acct'] -%>"
}

data "google_project" "project" {
}

resource "google_billing_budget" "<%= ctx[:primary_resource_id] %>" {
  billing_account = data.google_billing_account.account.id
  display_name = "<%= ctx[:vars]['display_name'] %>"

  budget_filter {
    projects = ["projects/${data.google_project.project.number}"]
    credit_types_treatment = "EXCLUDE_ALL_CREDITS"
    services = ["services/24E6-581D-38E5"] # Bigquery
  }

  amount {
    specified_amount {
      currency_code = "USD"
      units = "100000"
    }
  }

  threshold_rules {
    threshold_percent = 0.5
  }
  threshold_rules {
    threshold_percent = 0.9
    spend_basis = "FORECASTED_SPEND"
  }
}
